﻿using System;

using System.Collections.Generic;
using System.Text;
using Silvermoon.Shapes;
using System.Drawing;
using Silvermoon.OpenGL;
using Silvermoon.Utils;

using Silvermoon.Core;

using Silvermoon.Windows;
using Silvermoon.Interfaces;
using Silvermoon.Controls.Base;
using Silvermoon.UI;

namespace Silvermoon.Controls.Sys
{
    /// <summary>
    /// Control to be used in <see cref="T:Keyboard"/>.
    /// </summary>
    public class KeyButton : Button
    {
        private static readonly VisualStateManager manager = new VisualStateManager();

        public KeyButton()
            : base()
        {
            ControlFlags &= ~(ControlFlags.CanFocus | ControlFlags.HitTestVisible);
            Command = Keyboard.KeyCommand;
            StateManager = manager;
        }


        public string Keys { get; set; }
        public bool IsControl { get; set; }
        public bool IsSpace { get; set; }

        public override bool CanFocus
        {
            get { return false; }
        }

        protected override Shape CreateDefaultBackground()
        {
            return PhoneColors.MediumDark;
        }

        protected internal override void OnTouchDown(TouchEventArgs e)
        {
            e.Cancel = true;   // permits that any ancestor control get's the focus.
            base.OnTouchDown(e);
        }

        protected internal override void OnTouchUp(TouchEventArgs e)
        {
            e.Handled = true;
            e.AllowDoubleTap = true;
            base.OnTouchUp(e);
        }

        protected override void OnLayout()
        {
            base.OnLayout();
            if (IsPressed)
            {
                TextColor = PhoneColors.Black;
                Color = PhoneColors.Light;
            }
            else
            {
                TextColor = PhoneColors.Text;
                Color = IsControl ? PhoneColors.MediumDark2 : PhoneColors.MediumDark;
            }
            //Background.Color = IsPressed ? PhoneColors.Light : Color;
        }


    }
}

